<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-xs-12">
		<div class="btn-group m-b-1" role="group">
			<?php echo admin_tab_active($menu['pay']['tab'], 'cate');?>
		</div>
	</div>
</div>
<div class="row">
<a href="<?php echo url("pay-cate"); ?>" style="margin:5px 10px; text-decoration:underline; color:#3399FF">分类管理</a> > <a href="<?php echo url("pay-cateprice-$cid"); ?>" style="margin:5px 10px; text-decoration:underline; color:#3399FF"><?php echo $cate_name;?>的价格段</a> > <?php echo $cate_price_name;?>的商品名称
</div>
<div class="row">
	<div class="col-lg-12">
		<div class="card">
			<div class="table-responsive">
				<form action="<?php echo url('pay-categoodsadd');?>" method="POST">
					<input type="hidden" id="cid" name="cid" value="<?php echo $cid;?>">
					<input type="hidden" id="pid" name="pid" value="<?php echo $pid;?>">
					<table style="margin-top:10px;" align="center">
						<tr>	
							<td>商品名称：</td>
							<td><input type="text" id="name" name="name" class="form-control"></td>
							<td><button type="button" class="btn btn-primary submit">添加</button></td>
						</tr>				
					</table>
				</form>
				<form action="<?php echo url('pay-categoods');?>" method="POST">
					<table class="table" style="min-width: 800px">
						<thead>
							<tr>
								<th class="text-center" width="60">删除</th>
								<th class="text-center" colspan="3">商品名称</th>
							</tr>
						</thead>
						<tbody id="userlist">
							<?php if($cate_goods){foreach($cate_goods as $l){ ?>
							<tr uid="<?php echo $l['id']; ?>">
								<td class="text-center"><input type="checkbox" name="delete" /></td>
								<td class="text-center"><input class="form-control" name="name[<?php echo $l['id'];?>]" value="<?php echo $l['name'];?>"></td>
							</tr>
							<?php }} ?>
						</tbody>
					</table>
					<button type="button" class="btn btn-warning" id="confirm" style="margin:5px 10px;">删除</button>
					<button type="button" class="btn btn-primary submit">提交修改</butotn>
				</form>
			</div>
			<hr class="m-t-0" />
		</div>
		<nav class="text-center"><ul class="pagination"><?php echo $pagination; ?></ul></nav>
	</div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<script>

$('.submit').click(function(){
	var jform = $(this).closest('form');
	var postdata = jform.serialize();
	$.xpost(jform.attr('action'), postdata, function(code, message){
		$.alert(message);
		if(code==1) setTimeout(function(){window.location.reload()}, 1500);
	});
	return false;
});

var jconfirm = $("#confirm");
var juserlist = $('#userlist');
// 删除选中的记录
jconfirm.on('click', function(){
	var jchecked = juserlist.find('input[name="delete"]').filter(function(){ return this.checked; });
	if(jchecked.length < 1) return alert("请选择要删除的商品名称");
	if(!window.confirm("确认删除？")) return false;
	jchecked.each(function() {
		jtr = $(this).parents('tr');
		var uid = jtr.attr('uid');
		$.xpost(xn.url('pay-categoodsdel'), {id:uid}, function(code, message) {
			if(code != 0) $.alert(message);
			jtr.remove();
		});
	});
});

$('#nav_pc li.pay, #nav_mobile li.pay').tab('show');
</script>